package pure.ui.groups 
{
	import pure.ui.core.ToggleButton;
	import pure.ui.RadioButton;
	import pure.ui.skins.ISkin;
	import pure.ui.skins.SelectableSkin;
	import flash.display.DisplayObjectContainer;
	import flash.events.EventDispatcher;
	import flash.geom.Point;
	
	/**
	 * 单选按钮组合
	 * @author Des
	 * <皮肤种类> ---- SelectableSkin
	 * 
	 * <TODO>可与StatePanel组合为TabBar！
	 */
	
public class RadioButtonGroup extends GroupBase
{
	public function RadioButtonGroup(x:Number, y:Number,skin:ISkin=null)
	{
		super(x, y,skin);
	}


	
	/*cache*/

	protected var _inited:Boolean = false;
	
	protected var ____changeObserver:Function;	// 选中项目改变回调方法

	
	
	/**
	 * 添加Item
	 * @param id
	 * @param x
	 * @param y
	 * @param itemSize
	 * @param skin
	 * @param hasLabel
	 **/
	override public function addItem(id:String,x:Number, y:Number, itemSize:Point = null, skin:ISkin = null,hasLabel:Boolean=true):void
	{
		super.addItem(id, x, y, itemSize, skin, hasLabel);
		if (!_inited)
		{
			_items[0].selected = true;
			_inited = true;
		}
	}
	
	/**
	 * 添加多Item
	 * @param itemsInfo
	 * @param x
	 * @param y
	 * @param itemSize
	 * @param layoutType
	 * @param layoutData
	 * @param hasLabel
	 **/
	override public function addItems(itemsInfo:Object,x:Number,y:Number,itemSize:Point = null,layoutType:int = 2,layoutData:Object = 4,hasLabel:Boolean=true):void
	{
		super.addItems(itemsInfo, x,y,itemSize, layoutType, layoutData, hasLabel);
		if (!_inited)
		{
			_items[0].selected = true;
			_inited = true;
		}
	}

	/**
	 * 观察选中项目改变
	 * @param observer		回调方法
	 **/
	public function setObserverChange(observer:Function):void
	{
		____changeObserver = observer;
	}
	
	
	
	
	
	/* ----------------------------------------------------    get / set    ----------------------------------------------------*/
	
	
	
	
	
	// 皮肤
	override public function set skin(value:ISkin):void
	{
		if (!value is SelectableSkin)
		{
			throw new Error('RadioButtonGroup::skin - 皮肤类型错误！');
		}
		super.skin = value;
	}	
	
	// 被选中id
	override public function set selectedId(value:String):void
	{
		this._selectedId = value;
		if (____changeObserver != null)
		{
			____changeObserver();
		}
	}

	// 被选中项目
	public function get selection():RadioButton
	{
		var item:RadioButton;
		for (var i:int = 0; i < _numItem; i++)
		{
			item = _items[i];
			if (item.id == selectedId)
			{
				return item;
			}
		}
		return null;
	}

	
	
	
	
	
	/* ----------------------------------------------------    private    ----------------------------------------------------*/

	
	
	
	
	
	/**
	 * 生成组件项目
	 * @param htmlLabel
	 * @param x
	 * @param y
	 * @param itemSize
	 * @param skin
	 **/
	override protected function _createItem(x:Number,y:Number,itemSize:Point,skin:ISkin,hasLabel:Boolean):IGroupItem
	{
		var item:RadioButton = new RadioButton(x, y, itemSize, skin, hasLabel);
		item.group = this;
		return item;
	}
}

}